﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.FriendRewardsUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import flash.text.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class FriendRewardsCell extends JPanel implements GridListCell {

        protected const HR_MARGIN:int = 40;

        protected var m_assetDict:Dictionary;
        protected var m_headerPanel:JPanel;
        protected var m_bodyPanel:JPanel;
        protected var m_footerPanel:JPanel;
        protected var m_imageIconLoader:Loader;
        protected var m_imagePanel:JPanel;
        protected var m_data:Object;
        protected var m_localeKey:String;

        public function FriendRewardsCell(_arg1:Dictionary, _arg2:LayoutManager=null, _arg3:String=null){
            this.m_assetDict = _arg1;
            this.m_localeKey = _arg3;
            super(new BorderLayout());
        }
        public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
        }
        public function setCellValue(_arg1):void{
            this.m_data = _arg1;
            var _local2:String = Global.gameSettings.getImageByName(this.m_data.itemName, "icon");
            this.m_imageIconLoader = LoadingManager.load(_local2, this.onImageLoaded, LoadingManager.PRIORITY_HIGH);
            this.buildCell();
        }
        public function getCellValue(){
            return (this.m_data);
        }
        public function getCellComponent():Component{
            return (this);
        }
        protected function buildCell():void{
            var m_picture:* = null;
            var ap:* = null;
            var imageHolder:* = (new (this.m_assetDict["card_available_selected"])() as DisplayObject);
            m_picture = (new EmbeddedArt.hud_no_profile_pic() as DisplayObject);
            ap = new AssetPane(m_picture);
            var friend:* = Global.player.findFriendById(this.m_data.uid);
            if (friend){
                LoadingManager.load(friend.snUser.picture, function (_arg1:Event):void{
                    m_picture = _arg1.target.content;
                    ap.setAsset(m_picture);
                });
            };
            var textHolder:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var senderName:* = Global.player.getFriendFirstName(this.m_data.uid);
            var giftText:* = ZLoc.t("Items", (this.m_data.itemName + "_friendlyName")).toUpperCase();
            var nameText:* = ((senderName + " ") + ZLoc.t("Dialogs", (this.m_localeKey + "_actionText_default")));
            if (Global.zooManager.isAnimal(this.m_data.itemName)){
                nameText = ((senderName + " ") + ZLoc.t("Dialogs", (this.m_localeKey + "_actionText_animal")));
            };
            var txt:* = nameText;
            var textWidth:* = 215;
            var fontName:* = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
            var fontAlign:* = TextFormatAlign.LEFT;
            var fontSize:* = 12;
            var fontColor:* = EmbeddedArt.blueTextColor;
            var nameLabel:* = ASwingHelper.makeMultilineText(txt, textWidth, fontName, fontAlign, fontSize, fontColor);
            var rTxt:* = giftText;
            var rTextWidth:* = 215;
            var rFontName:* = EmbeddedArt.TITLE_FONT;
            var rFontAlign:* = TextFormatAlign.LEFT;
            var rFontSize:* = 12;
            var rFontColor:* = EmbeddedArt.darkBlueTextColor;
            var rewardLabel:* = ASwingHelper.makeMultilineText(rTxt, rTextWidth, rFontName, rFontAlign, rFontSize, rFontColor);
            textHolder.appendAll(nameLabel, rewardLabel);
            ASwingHelper.setEasyBorder(textHolder, 0, 15);
            this.m_imagePanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_imagePanel.setPreferredSize(new IntDimension(imageHolder.width, imageHolder.height));
            if (Global.zooManager.isAnimal(this.m_data.itemName)){
                ASwingHelper.setSizedBackground(this.m_imagePanel, imageHolder);
            };
            var leftContainer:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            leftContainer.appendAll(ap, textHolder);
            var rightContainer:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            rightContainer.appendAll(this.m_imagePanel, ASwingHelper.horizontalStrut(5));
            var hrPanel:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var hrObj:* = new (this.m_assetDict["dialog_div"])();
            hrObj.width = (FriendRewardsDialogView.LIST_WIDTH - (this.HR_MARGIN * 2));
            var horizontalRule:* = new AssetPane(hrObj);
            hrPanel.append(horizontalRule);
            ASwingHelper.setEasyBorder(hrPanel, 0, 0, 4);
            this.append(leftContainer, BorderLayout.WEST);
            this.append(rightContainer, BorderLayout.EAST);
            this.append(hrPanel, BorderLayout.SOUTH);
        }
        protected function onImageLoaded(_arg1:Event):void{
            var _local2:DisplayObject;
            if (((this.m_imageIconLoader) && (this.m_imageIconLoader.content))){
                _local2 = this.m_imageIconLoader.content;
                _local2.scaleX = (_local2.scaleY = ASwingHelper.scaleToFit(_local2, this.m_imagePanel));
                if ((_local2 is Bitmap)){
                    (_local2 as Bitmap).smoothing = true;
                };
                this.m_imagePanel.append(new AssetPane(_local2));
            };
        }

    }
}//package Display.FriendRewardsUI 
